package com.ee.action;
/**
 * 登陆时验证码
 */
import java.io.ByteArrayInputStream;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ee.util.SecurityCode;
import com.ee.util.SecurityImage;
import com.opensymphony.xwork2.ActionSupport;

@Component("validCodeAction")
@Scope("prototype")
public class ValidCodeAction extends ActionSupport {
   
    private static final long serialVersionUID = 5633780176793520460L;
       //图片流
    private ByteArrayInputStream imageStream;
    @Override
    public String execute() throws Exception {
       try {
           HttpServletRequest request = ServletActionContext.getRequest();
            String securityCode = SecurityCode.getSecurityCode();
            imageStream = SecurityImage.getImageAsInputStream(securityCode);
            //放入session中
            request.getSession().setAttribute("securityCode", securityCode);
       } catch (Exception e) {
           e.printStackTrace();
       }
       return SUCCESS;
    }
    public ByteArrayInputStream getImageStream() {
       return imageStream;
    }
    public void setImageStream(ByteArrayInputStream imageStream) {
       this.imageStream = imageStream;
    }
}